﻿using System;
using System.Windows.Forms;

namespace ECS.Framework
{
    /// <summary>
    /// Common message box
    /// </summary>
    public static class CommonMessageBox
    {
        
        private const string MSG_BOX_TITLE_ERROR = "Error";
        private const string MSG_BOX_TITLE_INFO = "Information";
        private const string MSG_BOX_TITLE_WARNING = "Warning";
        private const string MSG_BOX_TITLE_CONFIRM = "Confirm";

        private const string COMMON_SAVE_COMPLETED = "completed save";
        private const string COMMON_CANCEL_SAVE = "Are you sure to cancel save?";
        private const string COMMON_CONFIRM_SAVE = "Are you sure to save?";
        private const string COMMON_CONFIRM_SAVE_CHANGE = "Are you sure to save change?";
        private const string COMMON_CONFIRM_DELETE = "Are you sure to delete?";
        private const string COMMON_DELETE_COMPLETED = "Delete completed";

        private static string _versionNumber = string.Empty;

        private static string GetDisplayVersion()
        {
            if (string.IsNullOrEmpty(_versionNumber))
            {
                //ECS.BLL.Component.SearchInfo search = new ECS.BLL.Component.SearchInfo();
                //VersionNumber = search.GetApplicationVersion();
                _versionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); ////Application.ProductVersion;
            }
            return string.Format(" ({0})", _versionNumber);
        }
        /// <summary>
        /// Show error message
        /// </summary>
        /// <param name="message"></param>
        public static void ShowMessageError(string message)
        {
            MessageBox.Show(message, MSG_BOX_TITLE_ERROR + GetDisplayVersion(), MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        /// <summary>
        /// Show error message with debug
        /// </summary>
        /// <param name="message"></param>
        public static void ShowMessageError(Exception handle, bool showTrace = false)
        {
            //debug  set showTrace = true
            showTrace = true;
            if (showTrace)
            {
                MessageBox.Show(handle.Message + "\r\n" + handle.StackTrace, MSG_BOX_TITLE_ERROR + GetDisplayVersion(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show(handle.Message, MSG_BOX_TITLE_ERROR + GetDisplayVersion(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// information messagebox
        /// </summary>
        /// <param name="message"></param>
        public static void ShowMessageInfo(string message, string caption = "")
        {
            MessageBox.Show(message, MSG_BOX_TITLE_INFO + GetDisplayVersion(), MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static void ShowMessageWarning(string message, string caption = "")
        {
            MessageBox.Show(message, MSG_BOX_TITLE_WARNING + GetDisplayVersion(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static DialogResult ShowMessageConfirmYNC(string message, string caption = "")
        {
            //Utils.ControlUtils.resetCursor();
            return MessageBox.Show(message, MSG_BOX_TITLE_CONFIRM, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
        }

        public static DialogResult ShowMessageConfirmYN(string message, string caption = "")
        {
            //Utils.ControlUtils.resetCursor();
            return MessageBox.Show(message, MSG_BOX_TITLE_CONFIRM, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
        }

        public static DialogResult ShowMessageCancelSave()
        {
            return CommonMessageBox.ShowMessageConfirmYN(COMMON_CANCEL_SAVE, "Confirm");
        }

        #region " Save Data "
        public static void displaySaveCompleted()
        {

            CommonMessageBox.ShowMessageInfo(COMMON_SAVE_COMPLETED, "Save Data");
        }

        public static DialogResult displayConfirmSave()
        {
            return ShowMessageConfirmYN(COMMON_CONFIRM_SAVE, "Save Data");
        }

        public static DialogResult displayConfirmSaveChanged()
        {
            return ShowMessageConfirmYNC(COMMON_CONFIRM_SAVE_CHANGE);
        }

        //public static DialogResult displayConfirmSaveChanged(string caption)
        //{
        //    return MessageBox.displayConfirmYNC(getApplicationMessage(ApplicationMessageID.COMMON_CONFIRM_SAVE_CHANGE), caption);
        //}

        //public static void displayFixAllErrorBeforeSave()
        //{
        //    MessageBox.displayError(getApplicationMessage(ApplicationMessageID.COMMON_FIX_ALL_ERROR), "Save Data");
        //}

        //public static void displayFixAllErrorBeforeSave(string caption)
        //{
        //    MessageBox.displayError(getApplicationMessage(ApplicationMessageID.COMMON_FIX_ALL_ERROR), caption);
        //}

        #endregion

        #region " Delete Data "
        public static DialogResult ShowMessageConfirmDelete()
        {
            return ShowMessageConfirmYN(COMMON_CONFIRM_DELETE, "Delete Data");
        }

        //public static DialogResult displayConfirmDelete(string caption)
        //{
        //    return ShowMessageConfirmYN(COMMON_CONFIRM_DELETE, caption);
        //}

        //public static DialogResult displayConfirmDeleteRecord()
        //{
        //    return MessageBox.displayConfirmYN(getApplicationMessage(ApplicationMessageID.COMMON_CONFIRM_DELETE_RECORD), "Delete Data");
        //}

        //public static DialogResult displayConfirmDeleteRecord(string caption)
        //{
        //    return MessageBox.displayConfirmYN(getApplicationMessage(ApplicationMessageID.COMMON_CONFIRM_DELETE_RECORD), caption);
        //}

        public static void ShowMessageaDeleteCompleted()
        {
            ShowMessageInfo(COMMON_DELETE_COMPLETED, "Delete Data");
        }

        //public static void displayDeleteCompleted(string caption)
        //{
        //    MessageBox.displayInfo(getApplicationMessage(ApplicationMessageID.COMMON_DELETE_COMPLETED), caption);
        //}
        #endregion
    }


}
